﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="newsuserlist.aspx.cs" Inherits="UI.system.page.news.memberlist" %>

<%@ Import Namespace="Model" %>
<%@ Import Namespace="DAL" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script src="/system/js/jquery.min.js"></script>
    <script src="/system/layui/layui.js"></script>
    <script src="/system/layui/lay/modules/laydate.js"></script>
    <script src="/system/js/common.js"></script>
    <script src="/system/js/md5.js"></script>
    <link rel="stylesheet" href="/system/layui/css/layui.css">
    <link rel="stylesheet" href="/system/css/iframe.css">
    <link rel="stylesheet" href="/css/common.css">
    <style>
        td img{border-radius:20px; width:40px; height:40px; float:left; margin-left:5px;}
        #batchfp{ visibility:hidden;}
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div class="layer-toolbar layui-form">
        <div class="layer-toolbar-left">
            <div style="float:left;">
            <%if(admin.Role==2){ %>
            可开通数量：<font class="green"><%=admin.UserCount %></font> &nbsp;&nbsp; 已开通数量：<font class="red"><%=hascount%></font> &nbsp;&nbsp; 剩余数量：<font class="green"><%= admin.UserCount-hascount %></font>
            <%} %>
            <a class="layui-btn layui-btn-small" id="batchfp" onclick="AdminSet_UserByIDs()">批量分配代理商</a>&nbsp;
            
            </div>
            
        </div>
        <div class="layer-toolbar-right">
            <div class="layui-input-inline lefts" style="width:100px; margin-right:5px;">
            <select id="state" name="state" lay-filter="state">
                <option value="-2">全部</option>
                <option value="-1">普通</option>
                <option value="0">未审核</option>
                <option value="1">已通过</option>
                <option value="2">已拒绝</option>
            </select>
            </div>
            <input id="begindate" type="text" name="title" placeholder="开始时间" autocomplete="off" class="layui-input" value="" style="width:100px;" onclick="layui.laydate({elem: this, format: 'YYYY-MM-DD'})"><div class="texts">-</div>
            <input id="enddate" type="text" name="title" placeholder="结束时间" autocomplete="off" class="layui-input" value="" style="width:100px;" onclick="layui.laydate({elem: this, format: 'YYYY-MM-DD'})">
            <input id="keyword" type="text" name="title" placeholder="用户名、手机号、ID、城市" autocomplete="off" class="layui-input" value="" style="width:190px;" onkeyup='CRM.Enter("#search")'>
            <a id="search" class="layui-btn layui-btn-small layui-btn-normal" onclick="Search()">搜索</a>
            <a class="layui-btn layui-btn-small" onclick="Search()">刷新</a>
        </div>
    </div>
    <div id="iframe" class="layer-iframe">
    <div class="layui-form">
    <table class="layui-table">
    <colgroup>
      <col width="50">
      <col>
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="100">
      <col width="120">
      <col width="120">
      <col width="120">
      <col width="120">
      <col width="180">
    </colgroup>
    <thead>
      <tr>
        <th id="allchoose"><input type="checkbox" name="" lay-skin="primary" lay-filter="allChoose"></th>
        <th>昵称</th>
        <th>入账详情</th>
        <th>头像</th>
        <th>所在省</th>
        <th>所在市</th>
        <th>性别</th>
        <th>余额</th>
        <th>关键词</th>
        <th>审核状态</th>
        <th>所属代理商</th>
        <th>到期日期</th>
        <th>创建时间</th>
        <th>操作</th>
      </tr>
    </thead>
    <tbody id="layer-table">
        <tr><td colspan="14" class="center">数据加载中...</td></tr>
    </tbody>
     <script id="data-table" type="text/html">
      {{#  layui.each(d, function(index, item){ }}
      <tr>
        <td><input type="checkbox" name="{{item.ID}}" lay-skin="primary" lay-filter="selected"></td>
        <td>{{item.NickName}}</td>
        <td>{{item.Business}}</td>
        <td><img src="{{item.HeadImg}}" /></td>
        <td>{{item.Province}}</td>
        <td>{{item.City}}</td>
        <td>{{item.Sex.ToSex()}}</td>
        <td>{{item.Money.toFixed(2)}}</td>
        <td>{{item.Keyword}}</td>
        <td><font class="{{item.State==1?'greens':'reds'}}">{{item.StateText}}</font></td>
        <td>{{item.AdminName}}</td>
        <td>{{item.EndDateText}}</td>
        <td>{{item.CreateDate}}</td>
        <td style="line-height:30px;">
        
        <%if(B.MyAdmin.Role==1){ %>
        <a class="layui-btn layui-btn-mini" onclick="AdminSet_User({{item.ID}})">分配代理商</a>
        <a class="layui-btn layui-btn-mini layui-btn-normal" onclick="Save_User({{item.ID}})">编辑</a>
        <a class="layui-btn layui-btn-mini layui-btn-danger" onclick="Delete_User(this,{{item.ID}})">删除</a>
        <%}else{ %>
        <a class="layui-btn layui-btn-mini layui-btn-normal" onclick="Save_User({{item.ID}})">编辑</a>
        <%} %>
        </td>
      </tr>
      {{#  }); }}
      </script>
  </table>
    </div>
    </div>
    <div id="layer-page" class="layer-page"></div>
    </form>
    <script>
        var ids = '';
        layui.use(['form', 'laytpl'], function () {
            $ = layui.jquery, form = layui.form(), laytpl = layui.laytpl;

            //全选
            form.on('checkbox(allChoose)', function (data) {
                ids = '';
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function (index, item) {
                    item.checked = data.elem.checked;
                    if (item.checked) {
                        ids += '' + item.name + ',';
                    }
                    //console.log(item.name);
                });
                
                form.render('checkbox');

                if (ids != "")
                    $("#batchfp").attr("style", "visibility:visible;");
                else
                    $("#batchfp").hide();

            });
            form.on('checkbox(selected)', function (data) {
                var childcount = $(data.elem).parents('table').find('tbody input[type="checkbox"]').length;
                var count = 0;
                ids = '';
                var child = $(data.elem).parents('table').find('tbody input[type="checkbox"]');
                child.each(function (index, item) {
                    if (item.checked) {
                        ids += '' + item.name + ',';
                        count = count + 1;
                    }
                });
                if (count > 0)
                    $("#batchfp").attr("style", "visibility:visible;");
                else
                    $("#batchfp").hide();
                    
                form.render('checkbox');

                if (count == childcount)
                    $("#allchoose div").addClass("layui-form-checked");
                else
                    $("#allchoose div").removeClass("layui-form-checked");

            });
            form.on("select(state)", function (data) {
                Search();
            });
            Init_Pager(1);
        });
        
        function Init_Pager(pageindex) {
            var data = {};
            data.act = "Find_NewsUser";
            data.pageindex = pageindex;
            data.parentid = $(".layui-table").attr("parentid");
            data.begindate = $("#begindate").val();
            data.enddate = $("#enddate").val();
            data.keyword = $("#keyword").val();
            data.state = $("#state").val();
            data.sign = GetSign(data.act);
            console.log(data);
            Loading();
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    Pager(json.data.list, json.data.count);
                }
                else {
                    LayerBox.Error(json.msg);
                }
            });
        };

        function Save_User(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/user/useradd.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                var title = id == 0 ? "新增" : "修改";
                window.parent.LayerBox.Show(title + "用户", html, 380, 330, null, function (form) {                  
                    var data = form;
                    data.act = "Save_User";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };

        function Power_User(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/set/userpower.aspx?id=" + id, function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("设置权限", html, 750, 680, null, function (form) {
                    var data = {};
                    data.power = CRM.ListValue("#userpower input[name='power']:checked");
                    if (CRM.ListValue("#oa_power input[name='power']:checked").length) {
                        data.power += ",oa-menu";
                    }
                    if (CRM.ListValue("#customer_power input[name='power']:checked").length) {
                        data.power += ",customer-menu";
                    }
                    if (CRM.ListValue("#order_power input[name='power']:checked").length) {
                        data.power += ",order-menu";
                    }
                    if (CRM.ListValue("#product_power input[name='power']:checked").length) {
                        data.power += ",product-menu";
                    }
                    if (CRM.ListValue("#finance_power input[name='power']:checked").length) {
                        data.power += ",finance-menu";
                    }
                    if (CRM.ListValue("#job_power input[name='power']:checked").length) {
                        data.power += ",job-menu";
                    }
                    if (CRM.ListValue("#report_power input[name='power']:checked").length) {
                        data.power += ",report-menu";
                    }
                    if (CRM.ListValue("#set_power input[name='power']:checked").length) {
                        data.power += ",set-menu";
                    }
                    data.act = "Power_User";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    Ajax.Post("/tools/API.ashx", data, function (r) {
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                LayerBox.Close.ByAll();
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };


        function Delete_User(o, id) {
            LayerBox.Confirm("您确定要删除吗？", function () {
                Delete_Table(o, id, "Delete_User");
            });
        };

        function RoleSet_User(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/user/roleset.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("级别设置", html, 380, 180, null, function (form) {
                    var data = form;
                    data.act = "RoleSet_User";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        function Set_UserKeyword(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/user/setkeyword.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("关键词", html, 380, 280, null, function (form) {
                    var data = form;
                    data.act = "Set_UserKeyword";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        function AdminSet_User(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/news/newsadminset.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("分配代理商", html, 380, 380, null, function (form) {
                    var data = form;
                    data.act = "AdminSet_User";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        function Audit_User(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/user/useraudit.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("审核会员", html, 380, 380, null, function (form) {
                    var data = form;
                    data.act = "Audit_User";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
        /*批量分配*/
        function AdminSet_UserByIDs() {
            if (ids != "") {
                LayerBox.Loading();
                Ajax.Get("/system/page/news/newsadminset.aspx?v=" + Math.random(), function (html) {
                    LayerBox.Close.ByAll();
                    window.parent.LayerBox.Show("批量分配代理商", html, 380, 380, null, function (form) {
                        var data = form;
                        data.act = "Batch_AdminSet_User";
                        data.ids = ids;
                        data.sign = GetSign(data.act);
                        LayerBox.Loading();
                        Ajax.Post("/tools/Admin.ashx", data, function (r) {
                            LayerBox.Close.ByAll();
                            var json = $.parseJSON(r);
                            if (json.state) {
                                LayerBox.Success(json.msg, 500, function () {
                                    $("#batchfp").hide();
                                    Search();
                                });
                            }
                            else {
                                LayerBox.Error(json.msg);
                            }
                        });
                    });
                });
            }
        };


        var timer;
        function autoplay() {
            if ($("#autoreflash").prop("checked")) {
                $("#timepanel").show();
                autoreflash();
            } else {
                $("#caltimes").html("60");
                $("#timepanel").hide();
                clearTimeout(timer);
            }
        };
        function toPlay() {
            $('#players').html('<audio autoplay="autoplay"><source src="http://www.zgwctx.com/css/shisong.aac" type="audio/mpeg"/></audio>');
        }
        function autoreflash() {
            var currtimes = parseInt($("#caltimes").html());
            if (currtimes == 1) {
                currtimes = 61;
                if ($("#autoreflash").prop("checked")) {
                    GetAuditCount();
                }
            }
            $("#caltimes").html(currtimes - 1);
            timer = setTimeout(autoreflash, 1000);
        };
        

        function GetAuditCount() {
            var data = {};
            data.act = "Get_AuditCount";
            Ajax.Post("/tools/Admin.ashx", data, function (r) {
                var json = $.parseJSON(r);
                if (json.state) {
                    if ($("#oldcount").html() != json.data + "") {
                        $("#oldcount").html(json.data);
                        toPlay();
                    }
                }
            });
        };
        <%if(admin.Role==1){ %>
        autoreflash();
        GetAuditCount();
        <%} %>

        function Update_User_Money(id) {
            LayerBox.Loading();
            Ajax.Get("/system/page/user/balance.aspx?id=" + id + "&v=" + Math.random(), function (html) {
                LayerBox.Close.ByAll();
                window.parent.LayerBox.Show("用户余额", html, 380, 200, null, function (form) {
                    var data = form;
                    data.act = "Update_Money";
                    data.id = id;
                    data.sign = GetSign(data.act);
                    LayerBox.Loading();
                    Ajax.Post("/tools/Admin.ashx", data, function (r) {
                        LayerBox.Close.ByAll();
                        var json = $.parseJSON(r);
                        if (json.state) {
                            LayerBox.Success(json.msg, 500, function () {
                                if (id == 0) {
                                    $(".layui-laypage").remove();
                                    Init_Pager(1);
                                } else {
                                    var currpage = 1;
                                    if ($(".layui-laypage-curr em").length > 0) {
                                        currpage = $(".layui-laypage-curr em")[1].innerHTML;
                                    }
                                    Init_Pager(currpage);
                                }
                            });
                        }
                        else {
                            LayerBox.Error(json.msg);
                        }
                    });
                });
            });
        };
</script>
</body>
</html>

